package com.java.jvalidator.framework.validator;

import com.java.jvalidator.framework.TypeUtil;
import com.java.jvalidator.framework.ValidationException;
import com.java.jvalidator.framework.config.Parameters;

public class NotEmptyValidator extends AbstractValidator {
	private static Validator instance = new NotEmptyValidator();

	public static Validator getInstance() {
		return instance;
	}

	protected boolean beginValidate(Object target, String fieldName, Parameters param) throws ValidationException {
		Object fieldValue = TypeUtil.getPropertyValue(target, fieldName);

		if ((fieldValue instanceof String)) {
			return !TypeUtil.isStringNullOrEmpty((String) fieldValue);
		}

		return fieldValue != null;
	}
}